﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Evaluant.NLinq
{
    public static class TypeResolver
    {
        static List<Assembly> assemblies = new List<Assembly>();

        public static void RegisterAssembly(Assembly assembly)
        {
            assemblies.Add(assembly);
        }

        public static Type ResolveType(string fullname)
        {
            IEnumerable<Assembly> assemblies;
#if !SILVERLIGHT
            if(TypeResolver.assemblies.Count == 0)
                IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
            else
                assemblies=TypeResolver.assemblies;
#else
            assemblies = TypeResolver.assemblies;
#endif

            foreach (Assembly a in assemblies)
            {
                Type type = a.GetType(fullname, false);

                if (type != null)
                    return type;
            }

            return null;
        }
    }
}
